#ifndef __COMM_HPP__
#define __COMM_HPP__

#include <iostream>
#include <unistd.h>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <cstdlib>
#include <fcntl.h>

using namespace std;
#define Mode 0666
#define Path "fifo"

class Fifo
{
public:
    Fifo(const string &path) : _path(path)
    {
        umask(0);
        //创建管道
        int n = mkfifo(_path.c_str(), Mode);
        if(n == 0)
        {
            cout << "fifo create success" <<endl;
        }
        else 
        {
            cout << "fifo fail, errno: " << errno << " stringerrno: " << strerror(errno) << endl;
        }
    }
    ~Fifo()
    {
        //删除管道，管道也是文件
        int n = unlink(_path.c_str());
        if(n == 0)
        {
            cout << "fifo remove success" <<endl;
        }
        else 
        {
            cout << "fifo remove, errno: " << errno << " stringerrno: " << strerror(errno) << endl;
        }
    }

private:
    string _path;//文件名+文件路径
};

#endif